<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="活动标题" prop="proName">
        <el-input
          v-model="queryParams.proName"
          placeholder="请输入活动标题"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['system:notice:add']"
          >新增</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:notice:edit']"
          >修改</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:notice:remove']"
          >删除</el-button
        >
      </el-col> -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="projectList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" align="center" prop="noticeId" width="50">
        <template #default="scope">
          <span>{{
            scope.$index +
            1 +
            (queryParams.domain.pageNum - 1) *
              queryParams.domain.pageSize
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="活动标题"
        align="center"
        prop="proName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="状态"
        align="center"
        prop="status"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="时间"
        align="center"
        prop="startEndTime"
        width="250"
      />
      <el-table-column
        label="指导老师"
        align="center"
        prop="teacherName"
        width="90"
      />
      <el-table-column
        label="团队成员"
        align="center"
        prop="otherStd"
        width="170"
        :show-overflow-tooltip="true"
      />
      
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="100"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="Setting"
            @click="goDetail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.domain.pageNum"
      v-model:limit="queryParams.domain.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="MyProjectList">
import {
  listNotice,
  getNotice,
  delNotice,
  addNotice,
  updateNotice,
} from "@/api/system/notice";
import { getProjectList, addProject ,delProject,getMyProjectList} from "@/api/pms/project";
import { addBanner } from "@/api/system/banner";
import useActivityStore from "@/store/modules/activity";
import { onActivated } from "vue";
const route = useRoute();
const router = useRouter();

const { proxy } = getCurrentInstance();
const { sys_notice_status, sys_notice_type } = proxy.useDict(
  "sys_notice_status",
  "sys_notice_type"
);

const projectList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dialogVisible = ref(false);
const proTypeOptions = ref([]);
const currentProId = ref('')

const data = reactive({
  form: {},
  queryParams: {
    domain: {
      isAsc: "true",
      orderByColumn: "",
      pageNum: 1,
      pageSize: 10,
      reasonable: true,
    },
    proName: "",
    proType: "",
    sortingType: "",
  },
  rules: {
    noticeTitle: [
      { required: true, message: "公告标题不能为空", trigger: "blur" },
    ],
    noticeType: [
      { required: true, message: "公告类型不能为空", trigger: "change" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询活动列表 */
function getList() {
  loading.value = true;
  getMyProjectList(queryParams.value).then((response) => {
    projectList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    noticeId: undefined,
    noticeTitle: undefined,
    noticeType: undefined,
    noticeContent: undefined,
    status: "0",
  };
  proxy.resetForm("noticeRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  currentProId.value = ''
  dialogVisible.value = true;
  title.value = "添加公告";
}

/**修改按钮操作 */
function handleUpdate(row) {
  reset();
   currentProId.value = row.id
  dialogVisible.value = true;
  title.value = "添加公告";
}

/**跳转活动详情 */
function goDetail(row) {
  reset();
  // const noticeId = row.noticeId || ids.value;
  // getNotice(noticeId).then((response) => {
  //   form.value = response.data;
  //   open.value = true;
  //   title.value = "修改公告";
  // });
  router.push({ path: `/home/detail`,query:{projectId:row.id,typeId:row.proType} });
}

/** 提交按钮 */
function submit(formData) {
  addProject(formData).then((response) => {
    proxy.$modal.msgSuccess("提交成功");
    getList();
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const proIds = row.id?[row.id] : ids.value;
  proxy.$modal
    .confirm('是否确认删除')
    .then(function () {
      return delProject(proIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
//匹配活动类型
function typeFilter(typeId) {
  return proTypeOptions.value.find((item) => item.id == typeId)
    ? proTypeOptions.value.find((item) => item.id == typeId).title
    : "";
}

onMounted(async () => {
  proTypeOptions.value = await useActivityStore().getType();
  getList();
});
</script>
